<template>
  <div class="index_box">
    <!-- 上下班tab标签页 -->
    <div class="index_tabs">
      <div
        class="gotowork"
        :class="tabsflg?'xuanzhong':''"
        @click="onClick()"
      >上班</div>
      <div
        class="gooffwork"
        :class="tabsflg?'':'xuanzhong'"
        @click="onClick()"
      >下班</div>
    </div>

    <!-- 公告 -->
    <div class="index_Notice">
      <div class="Notice_box">
        <img src="/static/images/voice.png" alt="公告" />
        <span>公告内容</span>
      </div>
      <span>&gt;</span>
    </div>

    <!-- 上班内容 -->
    <gotoworks v-if="tabsflg" :worklist="worklist" :remindlist="remindlist"></gotoworks>

    <!-- 下班内容 -->
    <gooffworks v-else :worklist="worklist"></gooffworks>

  </div>
</template>

<script>
import gooffworks from './components/gooffwork'
import gotoworks from './components/gotowork'
export default {
  props: {

  },
  data() {
    return {
      tabsflg: true,
      encryptedData: '',
      iv: '',
      user: '',
      worklist: [],
      remindlist: []
    };
  },
  computed: {
  },
  created() {
  },
  onShow() {
    // wx.reLaunch({
    //   url: '../success/main'
    // })
    wx.checkSession({
      success () {
        //session_key 未过期，并且在本生命周期一直有效
      },
      fail () {
        // session_key 已经失效，需要重新执行登录流程
        // wx.login() //重新登录
        wx.reLaunch({
         url: '../login/main'
        })
      }
    })

    let mobile =  wx.getStorageSync("mobile")
    this.request({
      url: this.baseUrl + '/api/edit/waterUser',
      data:{
        type: 1,
        mobile: mobile
      },
      method: 'POST',
    })
    .then(result=>{
			// console.log(result)
			if(result.status == 200){
        this.user = result.data.user_login
        // console.log(this.user.id)
        if(this.user.work_status == 0){
          this.tabsflg = false
        } else {
          this.tabsflg = true    
        }

        this.request({
          url: this.baseUrl + '/api/wechatapp/worklist',
          data:{
          },
          method: 'GET',
        })
        .then(result=>{
          // console.log(result.data)
          if(result.status == 200){
            this.worklist = result.data
            // console.log(this.worklist)
            // this.personal_center_content = result.data.personal_center_content; //介绍
          } else {
            return false
          }
        })

        this.request({
          url: this.baseUrl + '/api/wechatapp/worktoday',
          data:{
            water_user_id: this.user.id
          },
          method: 'GET',
        })
        .then(result=>{
          // console.log(result.data)
          if(result.status == 200){
            this.remindlist = result.data
            // console.log(this.remindlist)
            // this.personal_center_content = result.data.personal_center_content; //介绍
          } else {
            return false
          }
        })

			} else {
        wx.reLaunch({
          url: '../login/main'
        })
        return false
			}
    })

    // /api/wechatapp/notice
    this.request({
      url: this.baseUrl + '/api/wechatapp/notice',
      data:{
        cate_id: 1
      },
      method: 'GET',
    })
    .then(result=>{
			console.log(result.data)
			if(result.status == 200){
				// this.personal_center_content = result.data.personal_center_content; //介绍
			} else {
        return false
			}
    })

    // var that = this
    // // 判断用户是否授权登录
    // wx.getSetting({
    //   success: function (res) {
    //     // 判断是否授权
    //     if (res.authSetting['scope.userInfo']) {
    //       //获取用户信息
    //       wx.getUserInfo({
    //         success: function (res) {
    //           //用户已经授权过，添加用户信息
    //           // var that = this
    //           //wx.setStorageSync('nickName', res.userInfo.nickName)
    //           //wx.setStorageSync('avatarUrl', res.userInfo.avatarUrl)
    //         }
    //       });
    //     } else {
    //       wx.showToast({
    //         title: '请授权登录！',
    //         icon: 'none',
    //         duration: 1500,
    //         success: function () {
    //           //定时器，未授权1.5秒后跳转授权页面
    //           setTimeout(function () {
    //             wx.reLaunch({
    //               url: '../login/main',
    //             })
    //           }, 1500);
    //         }
    //       })
    //     }
    //   }
    // })
  },
  onLoad() {
    
  },
  mounted() {
  },
  watch: {

  },
  methods: {
    onClick() {
      if(!this.tabsflg){
        this.tabsflg = true
        // /api/wechatapp/workuser
        this.request({
          url: this.baseUrl + "/api/wechatapp/workuser",
          data: {
            id: this.user.id,
            work_status: 1
          },
          method: "POST",
        })
        .then((result) => {
          // console.log(result)
          if (result.status == 200) {
            // console.log(result)
            this.request({
              url: this.baseUrl + '/api/wechatapp/worklist',
              data:{
              },
              method: 'GET',
            })
            .then(result=>{
              // console.log(result.data)
              if(result.status == 200){
                this.worklist = result.data
                // this.personal_center_content = result.data.personal_center_content; //介绍
              } else {
                return false
              }
            })
          } else {
            // wx.showToast({
            //   title: result.msg,
            //   icon: "none",
            // });
          }
        })
      } else {
        this.tabsflg = false
        this.request({
          url: this.baseUrl + "/api/wechatapp/workuser",
          data: {
            id: this.user.id,
            work_status: 0
          },
          method: "POST",
        })
        .then((result) => {
          // console.log(result)
          if (result.status == 200) {
            // console.log(result)
            this.request({
              url: this.baseUrl + '/api/wechatapp/worklist',
              data:{
              },
              method: 'GET',
            })
            .then(result=>{
              // console.log(result.data)
              if(result.status == 200){
                this.worklist = result.data
                // this.personal_center_content = result.data.personal_center_content; //介绍
              } else {
                return false
              }
            })
          } else {
            // wx.showToast({
            //   title: result.msg,
            //   icon: "none",
            // });
          }
        })
      }
    },
  },
  components: {
    gooffworks,
    gotoworks
  },
};
</script>

<style  >
page {
  background-color: #f5f5f5;
}
.index_tabs {
  display: flex;
  justify-content: space-between;
  padding: 20rpx;
  background: rgb(25, 119, 255);
}
.gotowork {
  width: 50%;
  padding: 10rpx;
  text-align: center;
  border-radius: 5rpx;
}
.gotowork {
  width: 50%;
  padding: 10rpx;
  text-align: center;
  border-radius: 10rpx 0 0 10rpx;
  border: 1px solid #f5f5f5;
  border-right: none;
  color: white;
}
.gooffwork {
  width: 50%;
  padding: 10rpx;
  text-align: center;
  border-radius: 0 10rpx 10rpx 0;
  border: 1px solid #f5f5f5;
  border-left: none;
  color: white;
}
.xuanzhong {
  background: white;
  color: #1677ff;
  border: none;
}
.index_Notice {
  display: flex;
  justify-content: space-between;
  background-color: #fff9ed;
  padding: 15rpx;
  color: #ff6010;
}
.index_Notice .Notice_box {
  display: flex;
  flex-wrap: wrap;
}
.index_Notice img {
  width: 36rpx;
  height: 36rpx;
  margin-top: 4rpx;
  margin-right: 10rpx;
}
</style>
